/* 
Project: 		The Impact of Short-Term Employment for Low-Income Youth: Experimental 	
				Evidence from the Philippines
Authors: 		Emily A. Beam and Stella Quimbo

***********************************
Path: 			code/02_analysis
File name: 		table_a03.do 
***********************************

Purpose: 		Generates Appendix Table A3 

Inputs: 		spes_data.dta
				peval.dta

Outputs: 		table_a03.tex

Log: 			results/03_output/log_table_a03.log		

Last updated: 	18 November 2021
*/ 

cap log close 
log using "$output/log_table_a03.log",replace

use "$usedata_analysis/spes_data",clear 
collapse (sum) baseline,by(id_peso region _municipality_name)		
count // 35 observations 
decode id_peso,gen(temp)

// Clean id values 
gen t1 = word(temp,1)
gen t2 = word(temp,2)
replace t2 = "R11" if t2 == "11"
replace t2 = "R03" if t2 == "3"
replace t2 = "R01" if t2 == "NCR"

replace t1 = "0" + t1 if length(t1) == 1

gen peso_id = t2 + "_" + t1
gen _sample = 1

tempfile t1
save `t1',replace



use "$usedata_analysis/01_raw/peval.dta",clear

count 		// 55 observations 

merge 1:1 peso_id using `t1'


recode _sample . = 0

drop if _merge == 2 // 

// Manual adjustments to sample (reflecting using master_muni)

replace _sample = 0 if _municipality_name ==  8
replace _sample = 0 if _municipality_name ==  11

tab _sample



/*
summarize the following variables: 

program size						total_enrollment
share returning applicants			spes_babies_enrolled/total_enrollment
average total enrollment			avg_totalenroll
target any priority groups			_anytarget
conduct skills matching				_e4bskills_matching 
conduct location matching			_e4clocation_matching 
account for student preferences		_e4dstudentpreferences 
account for desired location		_e4edesired_location_work

have lgu 100% funded slots			_any_100lgu
lgu influence						_lgu_influence

relevant elegibility criteria 
	 grades							_d3rel_grades
	 income							_d3rel_income
	 exam (administered)			_d3rel_exam
	 referrals						_d3rel_referrals
	 lgu rec						_d3rel_lgu
	 
*/ 

gen _share_ret = spes_babies_enrolled/total_enrollment



// _d5c_lce: Does the local chief executive take part in the selection process?
// Once you have a set of eligible applicants, what are the criteria for selecting SPES beneficiaries?  (notes LGU)
gen _lgu_influence = _d3rel_lgu == 1 | _d5c_lce == 1 

gen _recruit_private = e3apeso_handle_pc == "1"
replace _recruit_private = .  if e3apeso_handle_pc == "MORE OF REFERRALS"

gen _d7a_orientation = d7ainformation_session == "1"
	replace _d7a_orientation = . if d7ainformation_session == "-99" | missing(d7ainformation_session)
* Add whether usually have oversubscription
loc v1 "total_enrollment _d1_any _anytarget _recruit_private _share_ret _public _b2_preorientation _d7a_orientation _lgu_influence  "
tabstat `v1',by(_sample)

** Label variables
label var total_enrollment "Average program enrollment, 2014–16"
label var _d1_any "Usually have oversubscription"
label var _anytarget "Set aside slots for specific groups"
label var _share_ret "Share returning participants"
label var _public "Public recruitment process"
label var _b2_preorientation "Hold info session before application"
label var _d7a_orientation "Hold orientation session for chosen beneficiaries"
label var _lgu_influence "Government officials influence selection" 
label var _recruit_private "Place any students with private employers"

estpost su `v1' if _sample==1
est store part

estpost su `v1' if _sample==0
est store nopart


#delimit;

	esttab part nopart using "$tables_analysis/table_a03.tex", replace 
		refcat(,nolabel)
		mtitle("Participating" "Non-participating" ) 
		cells(mean(fmt(2))) label booktabs nonum collabels(none) gaps 
		prehead( "\begin{tabular}{lcc}" "\toprule") 
		posthead(\hline) 
		prefoot() 
		postfoot("\bottomrule\multicolumn{3}{p{0.9\textwidth}}{\footnotesize{Notes: Data based on qualitative interviews with SPES program managers among municipalities invited to participate in study. Non-participating municipalities include programs that either declined to participate or accepted but did not have more eligible applicants than positions available. All questions aside from total enrollment ask about typical experiences over the past few years, excluding the current impact evaluation year.  Government oﬃcial inﬂuence deﬁned as whether the local mayor takes part in the selection process and/or the oﬃce considers referrals from government oﬃcials when determining who is chosen among eligible applicants.}} \end{tabular}" );
		

		log close;
		exit; 
